package enums;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;


public enum PayErrorEnum {

	PAY_CHANNEL_NOT_FOUND_ERROR("PAY9001000", "PAY_CHANNEL_NOT_FOUND_ERROR", "支付渠道未定义"),
	PAY_PARAM_IS_INVALID("PAY9002000", "PAY_PARAM_IS_INVALID", "参数非法"),
	PAY_PARAM_IS_BLANK("PAY9002001","PAY_PARAM_IS_BLANK", "参数为空"),
	PAY_PARAM_NOT_EQUALS("PAY9002002","PAY_PARAM_IS_BLANK", "参数不匹配"),
	PAY_ALIPAY_EXPECTION("PAY9005001","PAY_ALIPAY_EXPECTION", "支付宝支付异常"),
	PAY_DUPLICATE_KEY("PAY9005002","PAY_DUPLICATE_KEY", "订单号重复"),
	PAY_ORDER_NOT_EXIST("PAY9005003","PAY_ORDER_NOT_EXIST", "订单不存在"),
	PAY_ORDER_NOT_REFUND("PAY9005004","PAY_ORDER_NOT_REFUND", "订单不可退款"),
	PAY_ORDER_REFUND_COMPLETE("PAY9005005","PAY_ORDER_REFUND_COMPLETE", "订单已退款完成"),
	PAY_REFUND_ORDER_NOT_EXIST("PAY9005006","PAY_REFUND_ORDER_NOT_EXIST", "退款订单不存在"),
	PAY_NOTIFY_FORMAT_PARAM_EXCEPTION("PAY9006000","PAY_NOTIFY_FORMAT_PARAM_EXCEPTION", "异步回调格式化参数异常"),
	UN_KNOW_ERROR("PAY9999999", "UN_KNOW_ERROR", "未知异常"),

	;
	private String code;

	private String message;

	private String messageCN;

	private PayErrorEnum(String code, String message, String messageCN) {
		this.code = code;
		this.message = message;
		this.messageCN = messageCN;
	}

	public String getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}

	public String getMessageCN() {
		return messageCN;
	}

	public static PayErrorEnum getErrorEnum(String code) {
		if(StringUtils.isBlank(code)){
			return PayErrorEnum.UN_KNOW_ERROR;
		}
		return Arrays.stream(PayErrorEnum.values())
				.filter(p -> p.code.equals(code))
				.findAny()
				.orElse(PayErrorEnum.UN_KNOW_ERROR);
	}
}
